//
//  MCBLEManager.h
//  MCBLESDK
//
//  Created by Jany on 2017/11/29.
//  Copyright © 2017年 MillionConcept. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "MCBLEDefine.h"

//找到设备的委托
typedef void (^MCDiscoverPeripheralsBlock)(CBCentralManager *central,CBPeripheral *peripheral,NSDictionary *advertisementData, NSNumber *RSSI);

//更新（获取）Characteristics的value的block
typedef void (^MCReadValueForCharacteristicBlock)(CBPeripheral *peripheral,CBCharacteristic *characteristic,NSError *error);

//更新（获取）Characteristics的value的block
typedef void (^BBReadValueForCharacteristicBlock)(CBPeripheral *peripheral,CBCharacteristic *characteristic,NSError *error);

//找到服务的block
typedef void (^MCDiscoverServicesBlock)(CBPeripheral *peripheral,NSError *error);

//找到Characteristics的block
typedef void (^MCDiscoverCharacteristicsBlock)(CBPeripheral *peripheral,CBService *service,NSError *error);


@interface MCBLEManager : NSObject<CBCentralManagerDelegate,CBPeripheralDelegate>{

@public
    //已经连接的设备
    CBPeripheral *connectedPeripheral;
    //蓝牙连接状态
    BOOL connectFlag;
}

/**
 * 单例构造方法
 * @return MCBluetooth共享实例
 */
+ (instancetype)shareMCBluetooth;

/**
 扫描Peripherals
 */
- (void)scanPeripherals;

/**
 停止扫描
 */
- (void)cancelScan;

/**
 连接

 @param peripheral 外设
 */
- (void)connectToPeripheral:(CBPeripheral *)peripheral;

/**
 断开设备连接
 
 @param peripheral 已经连接的设备
 */
- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;

/**
 找到Peripherals的block |  when find peripheral
 */
- (void)setBlockOnDiscoverToPeripherals:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSDictionary *advertisementData, NSNumber *RSSI))block;

//设置获取到最新Characteristics值的block
- (void)setBlockOnReadValueForCharacteristic:(void (^)(CBPeripheral *peripheral,CBCharacteristic *characteristic,NSError *error))block;

//设置查找服务回叫
- (void)setBlockOnDiscoverServices:(void (^)(CBPeripheral *peripheral,NSError *error))block;

//设置查找到Characteristics的block
- (void)setBlockOnDiscoverCharacteristics:(void (^)(CBPeripheral *peripheral,CBService *service,NSError *error))block;

@end
